﻿using System;

namespace Inflector
{
    /// <summary>
    /// Selects the required form of the word, depending on the numeral.
    /// </summary>
    public class NumberInflector
    {
        private readonly string form0;
        private readonly string form1;
        private readonly string form2;

        /// <summary>
        /// Creates inflector for specified word.
        /// </summary>
        /// <param name="form0">Form for zero-like words. For example 0 "рублей".</param>
        /// <param name="form1">Form for one-like words. For example 1 "рубль".</param>
        /// <param name="form2">Form for two-like words. For example 2 "рубля".</param>
        public NumberInflector(String form0, String form1, String form2)
        {
            this.form0 = form0;
            this.form1 = form1;
            this.form2 = form2;
        }

        /// <summary>
        /// Inflects specified number for word injected via constructor.
        /// </summary>
        /// <param name="number">Number for inflection.</param>
        public String Inflect(Int32 number)
        {
            number = Math.Abs(number) % 100;

            if (number >= 10 && number <= 20)
                return form0;
            else
            {
                number %= 10;
                if (number == 0)
                    return form0;
                else if (number == 1)
                    return form1;
                else if (number < 5)
                    return form2;
                else
                    return form0;
            }
        }
    }

}
